#include <string.h>
#include "higv_cextfile.h"
#include "higv_language.h"
#include "hi_gv_parser.h"

#ifdef __cplusplus
#if __cplusplus
    extern "C"{
#endif
#endif /*  __cplusplus  */

#define LAN_CNT 14

static char *g_MulLan[LAN_CNT] = {LAN_EN,LAN_FR,LAN_ES,LAN_PT,LAN_DE,LAN_IT,LAN_ZH,LAN_ZH_TW,LAN_RU,LAN_JA,LAN_PO,LAN_AR,LAN_VN,LAN_HU};

static HI_VOID MultiLan_AddData()
{
    HI_S32 s32Ret;
    HI_U32 u32Index = 0;
    HIGV_HANDLE hDDB = 0;
    HIGV_DBROW_S stDbRow;

    HI_U32 StrSet[LAN_CNT] = {STR_EN,STR_FR,STR_ES,STR_PT,STR_DE,STR_IT,STR_ZH,STR_TW,STR_RU,STR_JA,STR_PO,STR_AR,STR_VN,STR_HU};

    /** Get DDB (default data base) handle*/
    s32Ret = HI_GV_ADM_GetDDBHandle(ADM_MULTILAN_STRINGID, &hDDB);

    if (HI_SUCCESS != s32Ret)
    {
        printf("Failed to add data, function:<%s>, retval %#x.\n", __FUNCTION__, s32Ret);
        return;
    }

    /** Disable DDB change*/
    HI_GV_DDB_EnableDataChange(hDDB, HI_FALSE);

    /** Clear DDB*/
    HI_GV_DDB_Clear(hDDB);

    /** Add data*/
    for (u32Index = 0; u32Index < LAN_CNT; u32Index++)
    {
        memset(&stDbRow, 0x00, sizeof(stDbRow));
        stDbRow.pData = &StrSet[u32Index];
        stDbRow.Size  = sizeof(HI_U32);
        HI_GV_DDB_Append(hDDB, &stDbRow);
    }

    /** Enable DDB change*/
    HI_GV_DDB_EnableDataChange(hDDB, HI_TRUE);
    HI_GV_Widget_SyncDB(MULTI_LANGUAGE_WIN_LISTBOX);

    return;
}


HI_S32 MULTI_LANGUAGE_SCENE_WIN_onhide(HIGV_HANDLE hWidget,HI_PARAM wParam, HI_PARAM lParam)
{
    return HIGV_PROC_GOON;
}

HI_S32 MULTI_LANGUAGE_SCENE_WIN_onshow(HIGV_HANDLE hWidget,HI_PARAM wParam, HI_PARAM lParam)
{
    HIGV_HANDLE hFontSet;

    if (HI_SUCCESS == HI_GV_FontSet_Create(&hFontSet))
    {
        (HI_VOID)HI_GV_FontSet_AddFont(simhei_font_text_20, "en;fr;es;pt;de;it;zh;zh_TW;ru;ja;hu", hFontSet);
        (HI_VOID)HI_GV_FontSet_AddFont(notosans_font_text_20, "po;vn", hFontSet);
        (HI_VOID)HI_GV_FontSet_AddFont(msuighur_font_text_25, "ar", hFontSet);
    }

    MultiLan_AddData();

    return HIGV_PROC_GOON;
}

HI_S32 MULTI_LANGUAGE_WIN_IMAGE1_ongesturetap(HIGV_HANDLE hWidget,HI_PARAM wParam, HI_PARAM lParam)
{
    (HI_VOID)HI_GV_Widget_Show(MAIN_WIN);
    (HI_VOID)HI_GV_Widget_Active(MAIN_WIN);
    (HI_VOID)HI_GV_Widget_Hide(MULTI_LANGUAGE_SCENE_WIN);

    return HIGV_PROC_GOON;
}

HI_S32 MULTI_LANGUAGE_WIN_LISTBOX_oncellselect(HIGV_HANDLE hWidget,HI_PARAM wParam, HI_PARAM lParam)
{
    HI_GV_Lan_Change(g_MulLan[wParam]);
    return HIGV_PROC_GOON;
}

HI_S32 MULTI_LANGUAGE_WIN_LISTBOX_onselect(HIGV_HANDLE hWidget,HI_PARAM wParam, HI_PARAM lParam)
{
    return HIGV_PROC_GOON;
}

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /*  __cplusplus  */
